<?php
/**
 * Introduction: 运费模板
 * @author: 杨陈鹏
 * @date: 2016/4/12 13:31
 * @email: yangchenpeng@cdlinglu.com
 */

namespace Admin\Controller\Logistics;


use Common\Controller\Admin\CommonController;

class FreightTplController extends CommonController
{


    /**
     * Introduction: 运费模板列表
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function lists()
    {

        $logic = D('Common/Transport', 'Logic');

        $data = $logic::getData(['stroe_id' => 0]);

        $this->data = $data['data'];

        $this->display();
    }

    /**
     * Introduction: 创建运费模板
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function create()
    {

        $this->display();
    }


    /**
     * Introduction: 修改运费模板
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function update()
    {

        $this->id = I('post.id');

        $logic = D('Common/Transport', 'Logic');

        $data = I('post.data');

        if( $data ) {

            //$this->ajaxReturn(json_decode($data,true));
            $this->ajaxReturn($logic::update(json_decode($data,true)));

        }

        $data = $logic::getOneData($this->id);

        $this->data = $data['data'];

        $this->display();
    }

    /**
     * Introduction: 获取配送地区
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function getSellArea()
    {

        $logic = D('Common/SellArea', 'Logic');

        $this->store_id = 1;

        $data = $logic::getData('level < 4', $this->store_id, 'id,name,pid');

        foreach ($data['data'] as $k => $v) {

            $datas[$v['id']] = $v;

        }

        //商家ID   为1时为后台数据

        $data = generateTree($datas);


        $group = A('Basic/Group');

        $this->data = $group::getHtmlTree($data, $this->areas, 0, ['name' => 'name', 'id' => 'id', 'pid' => 'pid', 'child' => 'child']);

        $this->display();
    }

    /**
     * Introduction: 添加运费模板主表数据
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function createTransport()
    {

        $data = I('post.data');

        $logic = D('Common/Transport', 'Logic');

        $this->ajaxReturn($logic::createTransport($data));

    }

    /**
     * Introduction: 添加运费模板附表数据
     * @author: 杨陈鹏
     * @date: 2016/4/12 13:31
     * @email: yangchenpeng@cdlinglu.com
     */
    public function createTransportExtend()
    {

        $data = I('post.data');

        $logic = D('Common/Transport', 'Logic');

        $this->ajaxReturn($logic::createTransportExtend($data));

    }


}